package io.renren.modules.work.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.R;
import io.renren.modules.basic.entity.MtCcWarehousPositionRelatEntity;
import io.renren.modules.basic.entity.MtCcWarehousRankEntity;
import io.renren.modules.basic.service.MtCcWarehousPositionRelatService;
import io.renren.modules.basic.service.MtCcWarehousRankService;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.work.entity.RankInfoEntity;
import io.renren.modules.work.service.RankInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author: liguanghao
 * @Date: 2019/11/14 15:42
 * @Version 1.0
 */
@Api(description = "库位获取")
@RestController
@RequestMapping("/rankInfo")
public class RankInfoController extends AbstractController {
    @Autowired
    private MtCcWarehousRankService mtCcWarehousRankService;
    @Autowired
    private RankInfoService rankInfoService;
    @Autowired
    private MtCcWarehousPositionRelatService mtCcWarehousPositionRelatService;

    @ApiOperation(value = "获取左右列信息",notes = "获取左右列信息")
    @PostMapping("rankInfo")
    public R rankInfo(@RequestBody Map<String,Object> params){
        String index=String.valueOf(params.get("index"));
         String row="R0"+index;
        List<MtCcWarehousRankEntity> mtCcWarehousRankEntities = mtCcWarehousRankService.list(new QueryWrapper<MtCcWarehousRankEntity>().eq("row_code", row));
        return R.ok().put("list",mtCcWarehousRankEntities);
    }

    @ApiOperation(value = "获取各列各层信息",notes = "获取各列各层信息")
    @PostMapping("positionRelatInfo")
    public R positionRelatInfo(@RequestBody Map<String,Object> params){
        List<MtCcWarehousRankEntity> mtCcWarehousRankEntities = mtCcWarehousRankService.list(new QueryWrapper<MtCcWarehousRankEntity>().le("id", 8));//主要是存入八个对象,几层就是几个对象,相当于写死
        return R.ok().put("mtCcWarehousRankList",mtCcWarehousRankEntities);
    }

    @ApiOperation(value = "库位信息详情添加",notes = "库位信息详情添加")
    @PostMapping("test")
    public R test(){
        for(int i=0;i<340;i++){
            MtCcWarehousPositionRelatEntity mtCcWarehousPositionRelatEntity=new MtCcWarehousPositionRelatEntity();
            mtCcWarehousPositionRelatEntity.setId(i+1);
            mtCcWarehousPositionRelatEntity.setCreateTime(new Date());
            mtCcWarehousPositionRelatEntity.setWarehousPositionId(i+1);
            mtCcWarehousPositionRelatEntity.setWarehousPositionName(mtCcWarehousRankService.getById(i+1).getAnotherName());
            mtCcWarehousPositionRelatService.save(mtCcWarehousPositionRelatEntity);
        }
        return R.ok();
    }
}
